package olegroshka.src.com.bofa.olegroshka.decorator;

import java.math.BigDecimal;

import olegroshka.src.com.bofa.olegroshka.analitics.RefundModel;

public class RefundDecorator implements Decorator<Object, Object> {

	private final RefundModel refundModel;
	
	public RefundDecorator(RefundModel refundModel) {
		this.refundModel = refundModel;
	}

	public BigDecimal decorate(Object in) {
		if( in == null ) {
			return BigDecimal.ZERO.setScale(2);
		} 
		//TODO ugly..
		if( in instanceof BigDecimal ) {
			return refundModel.calculate((BigDecimal)in);
		} else {
			throw new IllegalArgumentException("BigDecimal expected here, was: " + in);
		}
	}

}
